<?php

/**
 * This is the model class for table "medical_history".
 *
 * The followings are the available columns in table 'medical_history':
 * @property integer $id
 * @property string $pregnant
 * @property string $allergy
 * @property string $allergyyes
 * @property string $medical_list
 * @property string $major_injuries
 * @property string $lazy_eye
 * @property string $drooping_eyelid
 * @property string $galucoma
 * @property string $retinal
 * @property string $catatracts
 * @property string $crossed_eye
 * @property string $eye_infect
 * @property string $eye_injury
 * @property string $wearing_eyeglasses
 * @property string $wearing_contact
 * @property string $wearing_eyeglasses_old
 * @property string $wearing_contact_old
 * @property string $contact_type
 * @property string $comfortable
 * @property integer $personalinfo_id
 *
 * The followings are the available model relations:
 * @property PersonalInformation $personalinfo
 */
class MedicalHistory extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return MedicalHistory the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'medical_history';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('personalinfo_id', 'required'),
			array('personalinfo_id', 'numerical', 'integerOnly'=>true),
			array('pregnant, allergy, lazy_eye, drooping_eyelid, galucoma, retinal, catatracts, crossed_eye, eye_infect, eye_injury, wearing_eyeglasses, wearing_contact, comfortable', 'length', 'max'=>5),
			array('allergyyes, medical_list, major_injuries', 'length', 'max'=>200),
			array('wearing_eyeglasses_old, wearing_contact_old', 'length', 'max'=>50),
			array('contact_type', 'length', 'max'=>20),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, pregnant, allergy, allergyyes, medical_list, major_injuries, lazy_eye, drooping_eyelid, galucoma, retinal, catatracts, crossed_eye, eye_infect, eye_injury, wearing_eyeglasses, wearing_contact, wearing_eyeglasses_old, wearing_contact_old, contact_type, comfortable, personalinfo_id', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'personalinfo' => array(self::BELONGS_TO, 'PersonalInformation', 'personalinfo_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'pregnant' => 'Pregnant',
			'allergy' => 'Allergy',
			'allergyyes' => 'Allergyyes',
			'medical_list' => 'Medical List',
			'major_injuries' => 'Major Injuries',
			'lazy_eye' => 'Lazy Eye',
			'drooping_eyelid' => 'Drooping Eyelid',
			'galucoma' => 'Galucoma',
			'retinal' => 'Retinal',
			'catatracts' => 'Catatracts',
			'crossed_eye' => 'Crossed Eye',
			'eye_infect' => 'Eye Infect',
			'eye_injury' => 'Eye Injury',
			'wearing_eyeglasses' => 'Wearing Eyeglasses',
			'wearing_contact' => 'Wearing Contact',
			'wearing_eyeglasses_old' => 'Wearing Eyeglasses Old',
			'wearing_contact_old' => 'Wearing Contact Old',
			'contact_type' => 'Contact Type',
			'comfortable' => 'Comfortable',
			'personalinfo_id' => 'Personalinfo',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('pregnant',$this->pregnant,true);
		$criteria->compare('allergy',$this->allergy,true);
		$criteria->compare('allergyyes',$this->allergyyes,true);
		$criteria->compare('medical_list',$this->medical_list,true);
		$criteria->compare('major_injuries',$this->major_injuries,true);
		$criteria->compare('lazy_eye',$this->lazy_eye,true);
		$criteria->compare('drooping_eyelid',$this->drooping_eyelid,true);
		$criteria->compare('galucoma',$this->galucoma,true);
		$criteria->compare('retinal',$this->retinal,true);
		$criteria->compare('catatracts',$this->catatracts,true);
		$criteria->compare('crossed_eye',$this->crossed_eye,true);
		$criteria->compare('eye_infect',$this->eye_infect,true);
		$criteria->compare('eye_injury',$this->eye_injury,true);
		$criteria->compare('wearing_eyeglasses',$this->wearing_eyeglasses,true);
		$criteria->compare('wearing_contact',$this->wearing_contact,true);
		$criteria->compare('wearing_eyeglasses_old',$this->wearing_eyeglasses_old,true);
		$criteria->compare('wearing_contact_old',$this->wearing_contact_old,true);
		$criteria->compare('contact_type',$this->contact_type,true);
		$criteria->compare('comfortable',$this->comfortable,true);
		$criteria->compare('personalinfo_id',$this->personalinfo_id);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
	public function getFName()
        {       
        return $this->personal_information['FullName']; 
        }
}